package model.market;

import java.util.ArrayList;
import java.util.List;

import sun.reflect.misc.MethodUtil;

import model.market.AuctionEngine.PriceAndSplits;
import model.trader.Investor;

/**
 * This class allows traders to populate their portfolio with whatever they
 * like at the market price. the result should be a market equilibrium for the
 * next period.
 * @author andy
 *
 */
public class PortfolioInitEngine implements MarketEngine {

	public PeriodResults executeOrders(int period, AssetTradeRequests audit,
			double marketPrice) {
		PeriodResults results= new PeriodResults();
		results.setMarketPrice(marketPrice);
		
		List<Trade> executions=new ArrayList<Trade>();
		
		results.setExecutions(executions);
		
		
		for(Trade trade:audit.getDailyBuys()){
			
			if(!trade.isMarketOrder()&&trade.getLimitPrice()<marketPrice){
				
				continue;
			}
			
			Execution exec = new Execution(period,trade,null,trade.getQuantity()); 
			exec.setPrice(marketPrice);
			executions.add(trade);
		}
		
		for(Trade trade:audit.getDailySells()){
			if(!trade.isMarketOrder()&&trade.getLimitPrice()>marketPrice){
				continue;
			}
			Execution exec = new Execution(period,null,trade,trade.getQuantity()); 
			exec.setPrice(marketPrice);
			executions.add(trade);
		}
		return results;
	}

	@Override
	public PriceAndSplits discoverPrice(AssetTradeRequests audit,
			double marketPrice) {
		throw new RuntimeException("not implemented");
	}

}
